package com.ruoyi.web.controller.course;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.SysCourseTeacher;
import com.ruoyi.course.service.ISysCourseTeacherService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程和讲师关联Controller
 * 
 * @author YJF
 * @date 2023-05-17
 */
@RestController
@RequestMapping("/course/teacher")
public class SysCourseTeacherController extends BaseController
{
    @Autowired
    private ISysCourseTeacherService sysCourseTeacherService;

    /**
     * 查询课程和讲师关联列表
     */
    @PreAuthorize("@ss.hasPermi('course:teacher:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCourseTeacher sysCourseTeacher)
    {
        startPage();
        List<SysCourseTeacher> list = sysCourseTeacherService.selectSysCourseTeacherList(sysCourseTeacher);
        return getDataTable(list);
    }

    /**
     * 获取课程和讲师关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:teacher:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        SysCourseTeacher sysCourseTeacher = new SysCourseTeacher();
        sysCourseTeacher.setId(id);
        return AjaxResult.success(sysCourseTeacherService.selectSysCourseTeacherByCourseId(sysCourseTeacher));
    }

    /**
     * 新增课程和讲师关联
     */
    @PreAuthorize("@ss.hasPermi('course:teacher:add')")
    @Log(title = "课程和讲师关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCourseTeacher sysCourseTeacher)
    {
        return toAjax(sysCourseTeacherService.insertSysCourseTeacher(sysCourseTeacher));
    }

    /**
     * 修改课程和讲师关联
     */
    @PreAuthorize("@ss.hasPermi('course:teacher:edit')")
    @Log(title = "课程和讲师关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCourseTeacher sysCourseTeacher)
    {
        return toAjax(sysCourseTeacherService.updateSysCourseTeacher(sysCourseTeacher));
    }

    /**
     * 删除课程和讲师关联
     */
    @PreAuthorize("@ss.hasPermi('course:teacher:remove')")
    @Log(title = "课程和讲师关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysCourseTeacherService.deleteSysCourseTeacherByCourseIds(ids));
    }
}
